package com.example.day09.homework;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * 括号匹配
 */
public class Parenthesismatching {
    public static void main(String[] args) {

        Scanner scanner=new Scanner(System.in);
        String  str=scanner.nextLine();
        System.out.println(matching(str));

    }
    public  static  boolean   matching(String str){
        String     strle=str;
        LinkedList<Character> list=new LinkedList<>();
        char  first= strle.charAt(0);
        list.push(first);
        for(int i=1;i<strle.length();i++){
            Character cc=strle.charAt(i);

            if(list.isEmpty()){ //判断是否为空，如果链表为空直接添加
                list.push(cc);
            }else{
                if(isequal(list.getFirst(),cc)){
                    list.pop();
                }else {
                    list.push(cc);
                }
            }
        }
        if (list.isEmpty()){
            return  true;
        }else {
            return  false;
        }
    }

    //标比较两个字符是否匹配
    public static   boolean  isequal(Character c1,Character c2){
        if(c1=='['&&c2==']'||c1==']'&&c2=='['){
            return  true;
        }
        if(c1=='('&&c2==')'||c1==')'&&c2=='('){
            return  true;
        }
        if(c1=='{'&&c2=='}'||c1=='}'&&c2=='{'){
            return  true;
        }

        return  false;

    }
}
